package com.job.dao.Impl;

import com.job.dao.ResumeDao;
import com.job.model.Resume;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.query.Query;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository("resumeDao")
public class ResumeDaoImpl implements ResumeDao {
    private SessionFactory sessionFactory;
    /**
     * 获取的简历
     *
     * @param limitStrat
     * @param limitEnd
     * @return 简历列表
     */
    @Override
    public List<Resume> getResume(int limitStrat, int limitEnd) {
       Session session= sessionFactory.getCurrentSession();
       //todo
        return null;
    }

    /**
     * 根据用户id 获取用户的简历
     *
     * @param userId 用户id
     * @return 简历实体 或者是null
     */
    @Override
    public List<Resume> getResume(int userId) {
       Session session= sessionFactory.openSession();
        Query query= session.createQuery("FROM Resume as R where R.userId="+userId );
        return query.getResultList();
    }

    /**
     * 添加一份简历
     *
     * @param resume 简历
     */
    @Override
    public void addResume(Resume resume) {
        Session session=sessionFactory.openSession();
        session.save(resume);
    }


    @Override
    public void update(Resume resume) {
       Session session= sessionFactory.openSession();
       session.update(resume);
    }

    @Autowired
    public void setSessionFactory(SessionFactory sessionFactory) {
        this.sessionFactory = sessionFactory;
    }
}
